﻿using System;
using Framework.MVC;
using Identity.Model;
using Identity.IService;
using Framework.MVVM.Model;
using Identity.Service;
using Common.IService;
using Common.Service;

namespace FrontCenter.Models
{
    [ServiceAttribute(typeof(ILimitedService), typeof(LimitedService), "Instance")]
    [ServiceAttribute(typeof(ISaltService), typeof(SaltService), "Instance")]
    [ServiceAttribute(typeof(IVerifyCodeService), typeof(VerifyCodeService), "Instance")]
    [ServiceAttribute(typeof(ICodeService), typeof(CodeService), "Instance")]
    public class NewVerifyCode : AsyncModelBase, IContainsLimited,INewVerifyCode,INewLimited
    {
        #region Field

        private const string m_code = "code";
        private const string m_value = "value";

        private const string m_format = "{0}VerifyCode";

        #endregion Field

        #region AsyncModelBase

        protected override void OnInit(Type type)
        {
            this.OnBeginRequest();
            this.ContainsLimited(string.Format(m_format,Resource), string.Empty, string.Empty);
        }

        #endregion AsyncModelBase

        #region IContainsLimited

        public string LimitedCode { get; set; }

        public string LimitedValue { get; set; }

        public void OnContainsLimitedComplete(string key, bool entry)
        {
            this.NewVerifyCode(Resource, string.Empty, string.Empty);
        }

        public void OnContainsLimitedError(string key)
        {
            this.OnEndRequest();
        }

        #endregion IContainsLimited

        #region INewVerifyCode

        public void OnNewVerifyCodeComplete(string key, string value)
        {
            OnComplete(m_code, VerifyCode);
            OnComplete(m_value, value);
            this.NewLimited(string.Format(m_format, Resource), string.Empty, string.Empty);
        }

        public void OnNewVerifyCodeError(string key)
        {
            this.OnEndRequest();
        }

        public string VerifyCode
        { get; set; }

        public string Resource { get; set; }

        #endregion INewVerifyCode

        #region INewLimited

        public void OnNewLimitedComplete(string key, bool entry)
        {
            this.OnEndRequest();
        }

        public void OnNewLimitedError(string key)
        {
            this.OnEndRequest();
        }

        #endregion INewLimited
    }
}